﻿@page
@model ToolGood.SqlOnline.Pages.Admins.Admin.EditModel
@{
    Layout = "~/Pages/Shared/_Layout_Edit.cshtml";
}
<div style="overflow-x:hidden">
    <form id="edit-form">
        <input type="hidden" name="id" value="@Model.SysAdmin.Id" />
        @Html.AntiForgeryToken()
        <div class="layui-form" style="padding: 20px 30px 0 0;">

            <div class="layui-form-item">
                <label class="layui-form-label">登录名<span class="red"> *</span></label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="txt_name" value="@Model.SysAdmin.Name" disabled="disabled">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名<span class="red"> *</span></label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="txt_trueName" name="trueName" value="@Model.SysAdmin.TrueName" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="txt_jobNo" name="jobNo" value="@Model.SysAdmin.JobNo" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="txt_phone" name="phone" value="@Model.SysAdmin.Phone" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="txt_email" name="email" value="@Model.SysAdmin.Email" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">管理组</label>
                <div class="layui-input-block">
                    @foreach (var item in Model.Groups) {
                        <input type="checkbox" name="Groups[]" lay-skin="primary" value="@item.Id" title="@item.Name" @(Model.RelationshipDtos.Any(q => q.GroupId == item.Id).ToChecked()) />
                    }
                </div>
            </div>


            <div class="layui-form-item" style="text-align:center;padding-left: 30px;">
                <button type="button" class="layui-btn layui-btn-normal" onclick="save(this);"> &nbsp;&nbsp; 提 交 &nbsp;&nbsp; </button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeWindow();"> &nbsp;&nbsp; 关 闭 &nbsp;&nbsp; </button>
            </div>
        </div>

    </form>
</div>
@section js{
    <script>
        function save(obj) {
            if ($("#txt_name").val().length < 2) { layer.alert("请输入登录名"); $("#txt_name").focus(); return; }
            if ($("#txt_trueName").val().length < 3) { layer.alert("请输入姓名"); $("#txt_trueName").focus(); return; }

            $(obj).prop("disabled", true);
            var url = "./Ajax/EditAdmin";
            var data = $("#edit-form").serializeJson();
            $.adminModePost(url, data, function () {
                closeWindowAndReload();
          }, function (data) {
                $(obj).prop("disabled", false);
                if (data.message) {
                    layer.msg(data.message);
                } else {
                    layer.msg("出错了");
                }
            });
        }
    </script>
}
